home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 2
/
Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso
/
Aminet
/
dev
/
misc
/
egs.lha
/
EGS
/
EGS_Devels
/
Examples
/
Other
/
lines.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-02-17
|
9KB
|
367 lines
/*
** Author: Markus van Kempen
**
** Date: 12 Nov 1992
**
** Compiler : SAS 6.0
**
**
** This is a line drawing demo for the Amiga or EGS.
**
** For running under EGS please compile:
**
** sc link def EGS lines.c
**
*/
#include <stdlib.h>
#include <stdio.h>
#include <exec/types.h>
#include <exec/nodes.h>
#include <exec/lists.h>
#include <intuition/intuition.h>
#include <graphics/text.h>
#include <proto/exec.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
USHORT wakeup; /* Wake me up for event */
USHORT class; /* Intui event class */
USHORT code; /* Intui event code */
UBYTE *oldName;
int oldPri;
#ifndef EGS
struct Window *w;
struct RastPort *rp,*cdrp;
struct ViewPort *vp;
struct IntuiMessage *message;
#define MIX_CLOSEWINDOW CLOSEWINDOW
#define MIX_NEWSIZE NEWSIZE
#else
/*
** EGS includes & variables
**
**
*/
#include <egs/egsintui.h>
#include <egs/egsgfx.h>
#include <egs/proto/egsintui.h>
#include <egs/proto/egsgfx.h>
struct EG_RastPort *rp,*cdrp;
struct EI_Window *w;
struct EI_EIntuiMsg *message;
struct Library *EGSGfxBase;
struct Library *EGSIntuiBase;
#define MIX_CLOSEWINDOW EI_iCLOSEWINDOW
#define MIX_NEWSIZE EI_iNEWSIZE
#endif
/* Proto */
void crash(char *string);
void exit(int i);
/************************ Window Defines ***********************************/
#ifndef EGS
struct NewWindow nw = {
100,100, /* Starting corner */
300,100, /* Width, height */
2,1, /* detail, block pens */
MIX_CLOSEWINDOW | MIX_NEWSIZE, /* IDCMP flags */
WINDOWDEPTH | WINDOWDRAG | WINDOWCLOSE | GIMMEZEROZERO | WINDOWSIZING,
/* Window flags */
NULL, /* Pointer to first gadget */
NULL, /* Pointer to checkmark */
"Nervous Lines", /* title */
NULL, /* screen pointer */
NULL, /* bitmap pointer */
50,50,640,400, /* window not sized */
WBENCHSCREEN /* type of screen */
};
#else
/*
** EGS-EI_Window structure
**
*/
struct EI_NewWindow nw = {
100,100, /* Starting corner */
300,100, /* Width, height */
50,50,640,400, /* window not sized */
NULL, /* screen pointer */
/* sysGadget for the Window */
EI_WINDOWCLOSE | EI_WINDOWSIZE |
EI_WINDOWDRAG | EI_WINDOWBACK |
EI_WINDOWFRONT ,
NULL, /* Pointer to first gadget */
"Nervous Lines", /* title */
/* Flags */
EI_WINDOWACTIVE |
EI_SIZEBBOTTOM |
EI_GIMMEZEROZERO,
/* EIDCMP-FLAGS */
MIX_CLOSEWINDOW | MIX_NEWSIZE,
NULL, /* MsgPort * */
{ 3 ,1 ,0 ,2 ,1 ,3 ,1 }, /* WinColors */
NULL, /* MenuPtr */
NULL /* IntuiGfxPtr */
};
/*
*/
#endif
int x[2],y[2],xd[2],yd[2],co,ox[2][16],oy[2][16],xx[128],xlim,ylim;
/**
*
* main program - Since no command line data is used, and no file I/O
* is performed, we do not need _main from the library. We eliminate
* it by calling our main function '_main'.
*
**/
void main()
{
register short i;
register int k;
int run=1;
register long co;
register long j;
register long rot=0,blau=0,gruen=0;
/************************ Set-Up routines **********************************/
/* Let the auto init code open our libraries for us. */
oldPri = SetTaskPri(FindTask(0), -5);
oldName = FindTask(0)->tc_Node.ln_Name;
FindTask(0)->tc_Node.ln_Name = "Lines";
#ifndef EGS
w = OpenWindow(&nw);
rp = w->RPort; /* Get the raster port pointer */
vp = &w->WScreen->ViewPort; /* Get the view port pointer */
SetAPen(rp,3); /* Set foreground pen to white */
SetDrMd(rp,JAM1); /* Draw with foreground pen */
xlim = w->Width;
ylim = w->Height;
#else
/*
** EGS - Open EGS Libraries and call some
** EGS functions
**
*/
EGSGfxBase = OpenLibrary("egsgfx.library",0);
if (EGSGfxBase == NULL )
crash("Can't open egsgfx.library !");
EGSIntuiBase = OpenLibrary("egsintui.library",0);
if (EGSIntuiBase == NULL )
crash("Can't open egsintui.library !");
w = EI_OpenWindow(&nw);
rp = w->RPort;
EG_SetAPen(rp,0);
EG_SetDrMd(rp,0);
xlim = w->Width;
ylim = w->Height;
#endif
for(i=0;i<2;i++)
{
x[i] = rand() % xlim + 1;
y[i] = rand() % ylim + 1;
xd[i] = rand() % 10 + 1;
yd[i] = rand() % 10 + 1;
}
co = 1;
j = 0;
do {
#ifndef EGS
SetAPen(rp,co);
Move(rp,x[0],y[0]);
Draw(rp,x[1],y[1]);
if((rand() & 127) < 2)
{
++co;
if(co > 3) co = 1;
SetAPen(rp,co);
}
#else
/*
** EGS The equal EGS functions
**
**
*/
EG_SetAPen(rp,co);
EG_Move(rp,x[0],y[0]);
EG_Draw(rp,x[1],y[1]);
if (blau < 64)
blau++;
else
{
blau=0;
if (gruen < 64)
gruen++;
else
{
gruen=0;
if (rot < 64)
rot++;
else
{
rot=0;
}
}
}
co = ((rot*4)<<24) +
((gruen*4)<<16) +
((blau*4)<<8);
EG_SetAPen(rp,co);
#endif
for(i=0;i<2;i++)
{
ox[i][(j+10) & 15] = x[i];
oy[i][(j+10) & 15] = y[i];
x[i] += xd[i];
y[i] += yd[i];
if(x[i] < 2)
{
x[i] = 2;
xd[i] = -xd[i];
}
else if(x[i] > xlim)
{
x[i] = xlim;
xd[i] = -xd[i];
}
if(y[i] < 2)
{
y[i] = 2;
yd[i] = -yd[i];
}
else if(y[i] > ylim)
{
y[i] = ylim;
yd[i] = -yd[i];
}
if(((rand() >> 5) & 127) < 2)
{
if(xd[i] < 1) k = 1;
xd[i] = (rand() >> 5) & 7;
if(k == 1) xd[i] = -xd[i];
k = 0;
}
if(((rand() >> 5) & 255) < 50)
{
if(yd[i] < 1) k = 1;
yd[i] = (rand() >> 5) & 7;
if(k == 1) yd[i] = -yd[i];
k = 0;
}
}
++j;
message = (struct EI_EIntuiMsg *)GetMsg(w->UserPort);
if(message != NULL)
{
class = message->Class;
code = message->Code;
ReplyMsg((struct Message *)message);
switch(class)
{
case MIX_CLOSEWINDOW:
run = 0;
break;
case MIX_NEWSIZE:
xlim = w->Width;
ylim = w->Height;
break;
}
}
} while(run);
#ifndef EGS
CloseWindow(w);
SetTaskPri(FindTask(0), oldPri);
FindTask(0)->tc_Node.ln_Name = oldName;
#else
EI_CloseWindow(w);
crash(NULL);
#endif
}
#ifdef EGS
/*
** CloseLibs
*/
void crash(char *string)
{
if (string != NULL)
printf("%s\n",string);
if (EGSGfxBase != NULL)
CloseLibrary(EGSGfxBase);
if (EGSIntuiBase != NULL)
CloseLibrary(EGSIntuiBase);
SetTaskPri(FindTask(0), oldPri);
FindTask(0)->tc_Node.ln_Name = oldName;
exit(0);
}
#endif